package com.wh.controller;

import com.wh.common.ApiRestResponse;
import com.wh.exception.SytExceptionEnum;
import com.wh.model.pojo.Patient;
import com.wh.model.vo.PatientVo;
import com.wh.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.PushBuilder;
import javax.validation.Valid;
import java.util.List;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2022/11/19 9:01
 * @description:
 * @version:
 */
@RestController
public class PatientController {
    @Autowired
    private PatientService patientService;
    //添加患者信息
    @PostMapping("/patient/add")
    public ApiRestResponse addPatient(HttpServletRequest request, @Valid @RequestBody PatientVo patientVo){
        String id = patientService.insertInfo(patientVo);
        return ApiRestResponse.success(id);
    }

    //查询患者信息
    @GetMapping("/patient/info")
    public ApiRestResponse getPatientInfo(HttpServletRequest request, @RequestParam(value = "id")String patientId){
        Patient patient = patientService.getById(patientId);
        return ApiRestResponse.success(patient);
    }

    //查询患者列表信息，优选选中默认患者，无默认患者，默认选择第一个
    //查询患者信息
    @GetMapping("/patient/mylist")
    public ApiRestResponse getPatientList(HttpServletRequest request){
        List<Patient> patientList = patientService.getPatientList();
        return ApiRestResponse.success(patientList);
    }

    //删除患者信息
    @DeleteMapping("/patient/del")
    public ApiRestResponse deletePatient(HttpServletRequest request,@RequestParam(value = "id")String patientId){
        boolean b = patientService.removeById(patientId);
        return b == true ? ApiRestResponse.success(patientId) : ApiRestResponse.error(SytExceptionEnum.DELETE_FILED);
    }





}
